document.getElementById('login-form').addEventListener('submit', function(e) {
    e.preventDefault();
    
    const storedUsers = JSON.parse(localStorage.getItem('users') || '[]');
    const inputUsername = document.getElementById('username').value;
    const inputPassword = document.getElementById('password').value;
    const errorMsg = document.getElementById('error-message');

    errorMsg.textContent = '';

    const validUser = storedUsers.find(user => 
        user.username === inputUsername && 
        user.password === inputPassword
    );

    if (validUser) {
        // 存储登录状态并跳转
        localStorage.setItem('username', inputUsername);
        window.location.href = 'home.html'; // 修改跳转目标
    } else {
        errorMsg.textContent = '用户名或密码错误';
        errorMsg.style.display = 'block';
    }
});